<template>
	<view>
		<u-navbar title-color="#333" title-bold title-size="36" title="绑定新银行卡" :border-bottom="false"></u-navbar>
		<view class="sz-div u-m-t-22">
			<view class="item flex ">
				<view class="item-title">姓名</view>
				<u-input v-model="name" />
			</view>
			<view class="item flex ">
				<view class="item-title">身份证</view>
				<u-input v-model="identy" />
			</view>
		</view>
		<view class="sz-div u-m-t-22">
			<view class="item flex ">
				<view class="item-title">银行卡号</view>
				<u-input v-model="card_number" />
			</view>
			<view class="item flex flex_sb" @click="zixunShow=true">
				<view class="flex">
					<view class="item-title">开户银行</view>
					<view class="font_14_999">
						{{card_type?card_type:'请选择开户银行'}}
					</view>
				</view>
				<u-icon name="arrow-right" color="#333" size="28"></u-icon>
			</view>
			<view class="item flex ">
				<view class="item-title">预留手机号</view>
				<u-input v-model="mobile" />
			</view>
			<view class="item flex ">
				<view class="flex">
					<view class="item-title">验证码</view>
					<u-input v-model="sms_code" />
				</view>
				<u-verification-code :seconds="seconds" ref="uCode" @change="codeChange"></u-verification-code>
				<!-- <u-button @tap="getCode">{{tips}}</u-button> -->
				<view class="yzm-btn" @tap="getCode">
					{{tips}}
				</view>
			</view>
		</view>

		<u-popup v-model="zixunShow" mode="bottom" closeable border-radius="32">
			<view class="po-bikan">
				<view class="bk-title u-m-b-32 text_center">
					选择开户银行
				</view>
				<view class="po-top flex flex_sb flex_wrap">
					<view class="po-top-item flex flex_cen" v-for="(item,index) in yhlist" :key="index" :class="yhIndex==index?'po-top-item-sel':''" @click="yhIndex=index">
						<image class="yhsel" src="../../static/img/mine/yhsel.png" mode="" v-if="yhIndex==index"></image>
						<!-- <image class="po-icon" src="../../static/img/mine/wx-icon.png" mode=""></image> -->
						<view class="font_14_666 u-m-l-32">
							{{item.title}}
						</view>
					</view>
					
				</view>
				<view class="zhanwei2"></view>
				<view class="po-b flex flex_sb">
					<view class="po-btn1" @click="zixunShow=false">
						取消
					</view>
					<view class="po-btn2" @click="xzqr">
						确认
					</view>
				</view>
			</view>
		</u-popup>

		<u-toast ref="uToast"></u-toast>
		<view class="zhanwei2"></view>
		<view class="btn-bo">
			<button class="btn_login_btn" @click="$u.throttle(submit, 1000)">提交绑定</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:'',
				mobile:'',
				identy:'',
				card_number:'',
				card_type:'',
				sms_code:'',
				
				tips: '',
				seconds: 60,
				zixunShow: false,
				yhIndex:-1,
				bankList:[],
				yhlist:[{
					title:'中国银行',
				},{
					title:'工商银行',
				},{
					title:'农业银行',
				},{
					title:'建设银行',
				},{
					title:'交通银行',
				}]
			}
		},
		onLoad() {
			this.getbank()
		},
		methods: {
			getbank(){
				
				this.$api({
					url: '/setting',
					method: 'get',
				}).then(res => {
					if (res.code == 200) {
						this.bankList = res.data.bank
					}
				})
			},
			xzqr(){
				this.card_type = this.yhlist[this.yhIndex].title
				this.zixunShow=false
			},
			submit(){
				if(!this.name || !this.mobile || !this.identy || !this.card_number || !this.card_type || !this.sms_code){
					this.$u.toast('请填写完整');
					return
				}
				
				
				this.$api({
					url: '/editUserBank',
					method: 'post',
					data: {
						token:uni.getStorageSync("token"),
						name:this.name,
						mobile:this.mobile,
						identy:this.identy,
						card_number:this.card_number,
						card_type:this.card_type,
						sms_code:this.sms_code,
					},
				}).then(res => {
					if (res.code == 1) {
						this.$u.toast('添加成功');
						setTimeout(() => {
							uni.navigateBack()
						}, 1000);
						
					}
				})
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						this.$u.toast('验证码已发送');
						this.$refs.uCode.start();
					}, 2000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},

		}
	}
</script>

<style scoped lang="scss">
	.po-bikan {
		padding: 40rpx 32rpx;
		background: #F6F6F6;
		width: 100%;
		position: relative;
	
		.bk-title {
			font-weight: bold;
			font-size: 32rpx;
			color: #222222;
		}
		.po-b{
			width: 750rpx;
			height: 126rpx;
			background: #FFFFFF;
			box-shadow: 0rpx -8rpx 20rpx 2rpx rgba(0,0,0,0.06);
			padding: 8rpx 32rpx;
			position: absolute;
			bottom: 0;
			left: 0;
			
			.po-btn1{
				width: 330rpx;
				height: 80rpx;
				border-radius: 40rpx 40rpx 40rpx 40rpx;
				border: 1rpx solid #666666;
				font-size: 28rpx;
				color: #666666;
				font-weight: bold;
				text-align: center;
				line-height: 80rpx;
			}
			.po-btn2{
				width: 330rpx;
				height: 80rpx;
				background: linear-gradient( 177deg, #FFF7EA 0%, #ECA561 100%);
				border-radius: 48rpx 48rpx 48rpx 48rpx;
				font-size: 32rpx;
				color: #773E00;
				font-weight: bold;
				text-align: center;
				line-height: 80rpx;
			}
		}
		.po-top{
			
			.po-top-item{
				width: 334rpx;
				height: 80rpx;
				background: #FFFFFF;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				position: relative;
				margin-bottom: 16rpx;
				
				&-sel{
					border: 2rpx solid #E5A135;
				}
				
				.yhsel{
					position: absolute;
					bottom: 0;
					right: 0;
					width: 40rpx;
					height: 24rpx;
				}
				
				.po-icon{
					width: 52rpx;
					height: 52rpx;
				}
			}
		}
	}
	.sz-div {
		background-color: #fff;
		width: 686rpx;
		// height: 550rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: 0 auto;
		padding: 0 24rpx;

		.item {
			width: 100%;
			height: 110rpx;
			border-bottom: 1px solid #eee;

			.item-title {
				font-size: 28rpx;
				color: #000000;
				width: 180rpx;
			}

			.yzm-btn {
				width: 202rpx;
				height: 56rpx;
				background: linear-gradient(177deg, #FFF7EA 0%, #ECA561 100%);
				border-radius: 48rpx 48rpx 48rpx 48rpx;
				font-size: 24rpx;
				color: #333333;
				text-align: center;
				line-height: 56rpx;
			}

		}
	}

	.zhanwei2 {
		width: 750rpx;
		height: 142rpx;
	}

	.btn-bo {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		box-shadow: 0rpx -2rpx 8rpx 2rpx rgba(0, 0, 0, 0.14);
		padding-top: 14rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 9;

		.btn_login_btn {
			width: 686rpx;
			height: 90rpx;
			background: linear-gradient(177deg, #FFF7EA 0%, #ECA561 100%);
			border-radius: 46rpx 46rpx 46rpx 46rpx;
			// margin-top: 116rpx;
			font-size: 36rpx;
			color: #713005;
			line-height: 90rpx;
			margin-left: 32rpx;
			text-align: center;
			font-weight: bold;
		}
	}
</style>